package com.estun.backroundManagementService.modules.api.controller;

import com.estun.backroundManagementService.config.properties.FtpProperties;
import com.estun.backroundManagementService.modules.api.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;


@Controller
@RequestMapping("/app/file")
public class FileController {

    @Autowired
    private FileService fileService;

    @Autowired
    private FtpProperties ftpProperties;
    @ResponseBody
    @PostMapping("/uploadFile")
    public String uploadFile(@RequestParam("file") MultipartFile file) throws IllegalStateException, IOException {

        // TODO： 文件保存文件夹，后期可以换成配置文件中的内容
        String path = ftpProperties.getDownloadPath();
        String result = "";
        // 调用fileService保存文件
        result = fileService.storeFile(file, path);
//        logger.info("文件已保存至" + result);
        return result;
    }

}
